<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/10/9
  Time: 10:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用户登录</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>
    <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global_color.css"/>
</head>
<body class="index">
<div class="login_box">
    <form action="/admins/login.do" method="post">
        <table>
            <tr>
                <td class="login_info">账号：</td>
                <td colspan="2">
                    <input type="text" name="adminCode" class="width150"/>
                </td>
                <td class="login_error_info">
                    <span id="name_validate" class="required">${result.getFieldError("adminCode").defaultMessage}</span>
                </td>
            </tr>
            <tr>
                <td class="login_info">密码：</td>
                <td colspan="2">
                    <input type="password" name="password" class="width150"/>
                </td>
                <td>
                    <span id="password_validate"
                          class="required">${result.getFieldError("password").defaultMessage}</span>
                </td>
            </tr>
            <tr>
                <td class="login_info">验证码：</td>
                <td class="width70">
                    <input id="code" name="code" type="text" class="width70"/>
                </td>
                <td>
                    <img id="imgObj" src="/admins/getCode">
                    <a href="#" onclick="changeImg()">换一张</a>
                </td>
                <td>
                    <span id="validate" class="required">${codeError}</span>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="登录"></td>
                <td>
                    <span class="required">${error}</span>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
<script type="text/javascript">

    function changeImg() {
        var imgSrc = $("#imgObj");
        var src = imgSrc.attr("src");
        imgSrc.attr("src", chgUrl(src));
    }

    // 时间戳
    // 为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    function chgUrl(url) {
        var timestamp = (new Date()).valueOf();
        url = url.substring(0, 20);
        if ((url.indexOf("&") >= 0)) {
            url = url + "×tamp=" + timestamp;
        } else {
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }

</script>
</html>
